<%-- 
    Document   : BuscarUsuarios
    Created on : 3/04/2011, 05:18:42 PM
    Author     : Jhon
--%>
<%@page import="java.util.List"%>
<%@page import="control.Controller"%>
<%@page import="vo.VOUser"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="HTML.*"%>
<%@include file="CheckSession.jsp"%>
<% String search = request.getParameter("search");
   String busqueda = request.getParameter("busqueda");
   if(search== null || search==""){
    response.sendRedirect("./ListaUsuarios.jsp");
    return;
   }

   HtmlBody b = new HtmlBody("Users - Users List","");
   HtmlContent c = new HtmlContent("Users List");
   VOUser a = (VOUser) session.getAttribute("USER");
   if(a.isIsAdmin()){
   b.addUsuario(a.getHandle(), "Administrator");
   }else{
   b.addUsuario(a.getHandle(), "Usuario");
   }
   HtmlSideBar s = new HtmlSideBar(true);


   Controller con = Controller.getInstance();
   VOUser p;
   if(busqueda.equals("1")){
   try{
     p = con.findUser(search);
     }catch(Exception e){
    response.sendRedirect("./ListaUsuarios.jsp");
    return;
    }

   if(p==null || p.isIsAdmin()){
       response.sendRedirect("./ListaUsuarios.jsp");
        return;
   }
    session.setAttribute("SEARCHUSER", p);
    response.sendRedirect("./VerUsuario.jsp");

   }else if(busqueda.equals("2")){
   c.addSearchU("Search Users", "Usuario/BuscarUsuarios.jsp");

   List<VOUser> list = con.listUsers();
   if(list!=null && !list.isEmpty()){
      String[] datos ={"Handle","First Name","Last Name","Institution"};
       c.addInitLista("Users","600", datos);
      for(VOUser u: list){
        datos[0]=u.getHandle();
        datos[1]=u.getFirstName();
        datos[2]=u.getLastName();
        datos[3]=u.getInstitution();
        c.addDataLista(datos);
   }

   }
   c.addEndLista();
   }else{
   c.addSearchU("Search Users", "Usuario/BuscarUsuarios.jsp");
   List<VOUser> list = con.listUsers();
   if(list!=null && !list.isEmpty()){
      String[] datos ={"Handle","First Name","Last Name","Institution"};
       c.addInitLista("Users","600", datos);
      for(VOUser u: list){
        datos[0]=u.getHandle();
        datos[1]=u.getFirstName();
        datos[2]=u.getLastName();
        datos[3]=u.getInstitution();
        c.addDataLista(datos);
   }

   }
   c.addEndLista();

   }

   b.addContent(c.getContent());
   b.addSideBar(s.getBar());
    %>

    <%=b.getHtml()%>